/*
 * Created on Jul 24, 2004
 */
package org.vectrics.recruiter.struts.tag;

import org.apache.ecs.html.A;
import org.apache.ecs.html.IMG;
import org.vectrics.common.html.Cell;
import org.vectrics.common.html.Row;
import org.vectrics.common.html.Table;
import org.vectrics.common.html.TextHelper;

/**
 * @author mmoore
 */
public class UserBufferTable extends Table {

	private static final long serialVersionUID = -7512186871215748583L;
	
	private Cell contentCell = null;
	private Cell titleCell = null;
	//private Cell buttonCell = null;
	private Row buttonRow = null;
	private String contextPath = null;

	
	public UserBufferTable(String contextPath) {
		super();
		this.contextPath = contextPath;
		this.setCellPadding(0);
		this.setCellSpacing(0);
		makeHeaderRow();
		makeContentRow();
		this.makeBottomRow();
	}
	
	public Cell getContentCell() {
		return(contentCell);
	}
	
	public void setCaption(String title) {
		titleCell.addElement(TextHelper.getFont("bufferTitleFont", "<b>" + title + "</b>"));
	}
	
/*
	<td><img src="buf-0-0.gif" width="18" height="21"></td>
	<td background="buf-0-1.gif" width="50%"><font size="2" color="#000000">Candidates</font></td>
	<td><img src="buf-0-2.gif" width="14" height="21"></td>
	<td width="50%"><img src="buf-0-3.gif" width="100%" height="21"></td>
	<td><img src="buf-0-4.gif" width="4" height="21"></td>
*/	
	
	private void makeHeaderRow() {
		Row hdrRow = this.addRow();
		Cell hdrCell = hdrRow.addCell();
		Table hdrTable = new Table();
		hdrTable.setWidth("100%");
		hdrTable.setCellPadding(0);
		hdrTable.setCellSpacing(0);
		hdrCell.addElement(hdrTable);
		Row row = hdrTable.addRow();
		
		Cell iconCell = row.addCell();
		IMG iconImage = new IMG();
		iconImage.setWidth(18);
		iconImage.setHeight(21);
		iconImage.setSrc(this.contextPath + "/buf-0-0.gif");
		iconCell.addElement(iconImage);
		
		titleCell = row.addCell();
		titleCell.setVAlign("middle");
		titleCell.setBackground(this.contextPath + "/buf-0-1.gif");
		titleCell.setWidth("50%");

		Cell endTitleCell = row.addCell();
		IMG titleImage = new IMG();
		titleImage.setWidth(14);
		titleImage.setHeight(21);
		titleImage.setSrc(this.contextPath + "/buf-0-2.gif");
		endTitleCell.addElement(titleImage);
		
		Cell buttonCell = row.addCell();
		buttonCell.setWidth("50%");
		buttonCell.setAlign("right");
		buttonCell.setBackground(this.contextPath + "/buf-0-3.gif");
		Table buttonTable = new Table();
		buttonTable.setCellPadding(0);
		buttonTable.setCellSpacing(0);
		buttonCell.addElement(buttonTable);
		buttonRow = buttonTable.addRow();
		
		
		Cell endButtonCell = row.addCell();
		IMG endBtnImage = new IMG();
		endBtnImage.setWidth(4);
		endBtnImage.setHeight(21);
		endBtnImage.setSrc(this.contextPath + "/buf-0-4.gif");
		endButtonCell.addElement(endBtnImage);
		
	}

	
	private void makeContentRow() {
		Row contRow = this.addRow();
		Cell contCell = contRow.addCell();
		Table contTable = new Table();
		contTable.setWidth("100%");
		contTable.setCellPadding(0);
		contTable.setCellSpacing(0);
		contCell.addElement(contTable);
		Row row = contTable.addRow();

		Cell leftBorderCell = row.addCell();
		leftBorderCell.setBackground(this.contextPath + "/buf-outline-dot.gif");
		IMG dotImage = new IMG();
		dotImage.setWidth(1);
		dotImage.setHeight(1);
		dotImage.setSrc(this.contextPath + "/cleardot.gif");
		leftBorderCell.addElement(dotImage);
		
		Cell padCell = row.addCell();
		dotImage = new IMG();
		dotImage.setWidth(1);
		dotImage.setHeight(3);
		dotImage.setSrc(this.contextPath + "/cleardot.gif");
		padCell.setBgColor("#FFFFFF");
		padCell.addElement(dotImage);
		
		contentCell = row.addCell();
		contentCell.setWidth("100%");
		contentCell.setBgColor("#FFFFFF");

		padCell = row.addCell();
		dotImage = new IMG();
		dotImage.setWidth(1);
		dotImage.setHeight(3);
		dotImage.setSrc(this.contextPath + "/cleardot.gif");
		padCell.setBgColor("#FFFFFF");
		padCell.addElement(dotImage);
		
		
		Cell rightBorderCell = row.addCell();
		rightBorderCell.setBackground(this.contextPath + "/buf-outline-dot.gif");
		dotImage = new IMG();
		dotImage.setWidth(1);
		dotImage.setHeight(1);
		dotImage.setSrc(this.contextPath + "/cleardot.gif");
		rightBorderCell.addElement(dotImage);
		
	}

/*	
	<td><img src="buf-1-0.gif" width="6" height="4"></td>
	<td width="100%"><img src="buf-1-1.gif" width="100%" height="4"></td>
	<td><img src="buf-1-2.gif" width="6" height="4"></td>
	*/
	private void makeBottomRow() {
		Row hdrRow = this.addRow();
		Cell hdrCell = hdrRow.addCell();
		Table hdrTable = new Table();
		hdrTable.setWidth("100%");
		hdrTable.setCellPadding(0);
		hdrTable.setCellSpacing(0);
		hdrCell.addElement(hdrTable);
		Row row = hdrTable.addRow();
		
		Cell leftCell = row.addCell();
		IMG iconImage = new IMG();
		iconImage.setWidth(6);
		iconImage.setHeight(4);
		iconImage.setSrc(this.contextPath + "/buf-1-0.gif");
		leftCell.addElement(iconImage);
		
		Cell midCell = row.addCell();
		midCell = row.addCell();
		midCell.setBackground(this.contextPath + "/buf-1-1.gif");
		midCell.setWidth("100%");

		Cell rightCell = row.addCell();
		IMG rightImage = new IMG();
		rightImage.setWidth(6);
		rightImage.setHeight(4);
		rightImage.setSrc(this.contextPath + "/buf-1-2.gif");
		rightCell.addElement(rightImage);
	}

	
    protected void addButton(String fileName, String href) {
    	String path = this.contextPath + "/" + fileName;
		IMG btnImage = new IMG();
		btnImage.setWidth(14);
		btnImage.setHeight(14);
		btnImage.setSrc(path);
		btnImage.setBorder(0);
		A buttonLink = new A();
		buttonLink.setHref(href);
		buttonLink.addElement(btnImage);
		Cell buttonCell = buttonRow.addCell();
		buttonCell.addElement(buttonLink);

		Cell sepCell = buttonRow.addCell();
		IMG dotImage = new IMG();
		dotImage.setBorder(0);
		dotImage.setWidth(2);
		dotImage.setHeight(1);
		dotImage.setSrc(this.contextPath + "/cleardot.gif");
		sepCell.addElement(dotImage);
    }
	
}
